package com.ITD.service.Impl;


import com.ITD.mapper.StudentMapper;
import com.ITD.pojo.Student;
import com.ITD.service.StudentService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {

   @Autowired
    private StudentMapper studentMapper;

    @Override
    public String[] getNameList(String[] numList) {
        List<String> list=new ArrayList<>();
        for(String num : numList){
            int number;
            try{
                 number = Integer.parseInt(num);
            }
            catch (Exception e){
                list.add("此学号不存在");
                continue;
            }
            LambdaQueryWrapper<Student> lqw=new LambdaQueryWrapper<>();
            lqw.eq(Student::getStudent_id,number);
            if(studentMapper.selectOne(lqw)==null)
                list.add("此学号不存在");
            else
                list.add(studentMapper.selectOne(lqw).getName());
        }

        return list.toArray(new String[list.size()]);
    }
}
